package com.baway.login.model

import com.baway.common.entity.BaseResponse
import com.baway.common.entity.UserEntity
import com.baway.db.RoomDBUtils
import com.baway.db.entity.UserInfoEntity
import com.baway.login.api.LoginApiServer
import javax.inject.Inject

/**
 * Author: Jason Zhang
 * Date: 2025/8/29
 * Desc: 登录注册仓库层
 */
class LoginRepository @Inject constructor(private val apiServer: LoginApiServer) {

    private val userDao = RoomDBUtils.getDataBase().getUserInfoDao()


    suspend fun loginToServer(userName: String, pwd: String): BaseResponse<UserEntity> = apiServer.loginToServer(userName, pwd)

    suspend fun registerToServer(userName: String, pwd: String):BaseResponse<UserEntity> = apiServer.registerToServer(userName, pwd)

    suspend fun saveUserInfoToRoom(entity: UserInfoEntity) = userDao.insertUserInfo(entity)

    suspend fun queryUserInfoFromRoom(userId: Int ): UserInfoEntity = userDao.queryUserInfoById(userId)


}